package com.fc.mall.portal.service.impl;

import com.fc.mall.mapper.UmsMemberAccountChangeHistoryMapper;
import com.fc.mall.model.UmsMember;
import com.fc.mall.model.UmsMemberAccountChangeHistory;
import com.fc.mall.model.UmsMemberAccountChangeHistoryExample;
import com.fc.mall.portal.service.UmsMemberAccountChangeHistoryService;
import com.fc.mall.portal.service.UmsMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UmsMemberAccountChangeHistoryServiceImpl implements UmsMemberAccountChangeHistoryService {
    @Autowired
    private UmsMemberAccountChangeHistoryMapper memberAccountChangeHistoryMapper;
    @Autowired
    private UmsMemberService memberService;

    public int insertMemberAccountChangeHistory(UmsMemberAccountChangeHistory memberAccountChangeHistory)
    {
        if(memberAccountChangeHistory != null)
        {
            return memberAccountChangeHistoryMapper.insertSelective(memberAccountChangeHistory);
        }
        return 0;
    }

    @Override
    public List<UmsMemberAccountChangeHistory> queryAccountChangeHistoryList(Integer accountType) {
        UmsMember curMember = memberService.getCurrentMember();
        UmsMemberAccountChangeHistoryExample example = new UmsMemberAccountChangeHistoryExample();
        example.createCriteria().andMemberIdEqualTo(curMember.getId()).andAccountTypeEqualTo(accountType);
        example.setOrderByClause("create_time DESC");
        return memberAccountChangeHistoryMapper.selectByExample(example);
    }
}
